package com.itboy.mall.pms.skuinfo.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.pms.skuinfo.vo.MallSkuInfoVo;
import com.itboy.mall.pms.skuinfo.bo.MallSkuInfoQueryBo;
import com.itboy.mall.pms.skuinfo.bo.MallSkuInfoAddBo;
import com.itboy.mall.pms.skuinfo.bo.MallSkuInfoEditBo;
import com.itboy.mall.pms.skuinfo.service.IMallSkuInfoService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * sku信息Controller
 *
 * @author itboy
 * @date 2021-08-08
 */
@Validated
@Api(value = "sku信息控制器", tags = {"sku信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/skuInfo")
public class MallSkuInfoController extends BaseController {

    private final IMallSkuInfoService iMallSkuInfoService;

    /**
     * 查询sku信息列表
     */
    @ApiOperation("查询sku信息列表")
    @PreAuthorize("@ss.hasPermi('mall:skuInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<MallSkuInfoVo> list(@Validated MallSkuInfoQueryBo bo) {
        return iMallSkuInfoService.queryPageList(bo);
    }

    /**
     * 导出sku信息列表
     */
    @ApiOperation("导出sku信息列表")
    @PreAuthorize("@ss.hasPermi('mall:skuInfo:export')")
    @Log(title = "sku信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallSkuInfoVo> export(@Validated MallSkuInfoQueryBo bo) {
        List<MallSkuInfoVo> list = iMallSkuInfoService.queryList(bo);
        ExcelUtil<MallSkuInfoVo> util = new ExcelUtil<MallSkuInfoVo>(MallSkuInfoVo.class);
        return util.exportExcel(list, "sku信息");
    }

    /**
     * 获取sku信息详细信息
     */
    @ApiOperation("获取sku信息详细信息")
    @PreAuthorize("@ss.hasPermi('mall:skuInfo:query')")
    @GetMapping("/{skuId}")
    public AjaxResult<MallSkuInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("skuId") Long skuId) {
		return AjaxResult.success(iMallSkuInfoService.queryInfoById(skuId));
    }

    /**
     * 新增sku信息
     */
    @ApiOperation("新增sku信息")
    @PreAuthorize("@ss.hasPermi('mall:skuInfo:add')")
    @Log(title = "sku信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallSkuInfoAddBo bo) {
        return toAjax(iMallSkuInfoService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改sku信息
     */
    @ApiOperation("修改sku信息")
    @PreAuthorize("@ss.hasPermi('mall:skuInfo:edit')")
    @Log(title = "sku信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallSkuInfoEditBo bo) {
        return toAjax(iMallSkuInfoService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除sku信息
     */
    @ApiOperation("删除sku信息")
    @PreAuthorize("@ss.hasPermi('mall:skuInfo:remove')")
    @Log(title = "sku信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{skuIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] skuIds) {
        return toAjax(iMallSkuInfoService.deleteWithValidByIds(Arrays.asList(skuIds), true) ? 1 : 0);
    }
}
